package com.easemob.util;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.ComponentName;
import android.content.Context;
import android.content.res.Resources;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import java.util.zip.GZIPOutputStream;

public class EasyUtils
{
  private static Hashtable<String, String> resourceTable = new Hashtable();

  public static boolean isAppRunningForeground(Context paramContext)
  {
    ActivityManager localActivityManager = (ActivityManager)paramContext.getSystemService("activity");
    List localList = localActivityManager.getRunningTasks(1);
    return paramContext.getPackageName().equalsIgnoreCase(((ActivityManager.RunningTaskInfo)localList.get(0)).baseActivity.getPackageName());
  }

  public static String getTopActivityName(Context paramContext)
  {
    ActivityManager localActivityManager = (ActivityManager)paramContext.getSystemService("activity");
    List localList = localActivityManager.getRunningTasks(1);
    return ((ActivityManager.RunningTaskInfo)localList.get(0)).topActivity.getClassName();
  }

  public static String getTimeStamp()
  {
    Date localDate = new Date(System.currentTimeMillis());
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    return localSimpleDateFormat.format(localDate);
  }

  public static boolean writeToZipFile(byte[] paramArrayOfByte, String paramString)
  {
    FileOutputStream localFileOutputStream = null;
    GZIPOutputStream localGZIPOutputStream = null;
    try
    {
      localFileOutputStream = new FileOutputStream(paramString);
      localGZIPOutputStream = new GZIPOutputStream(new BufferedOutputStream(localFileOutputStream));
      localGZIPOutputStream.write(paramArrayOfByte);
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      return false;
    }
    finally
    {
      if (localGZIPOutputStream != null)
        try
        {
          localGZIPOutputStream.close();
        }
        catch (IOException localIOException3)
        {
          localIOException3.printStackTrace();
        }
      if (localFileOutputStream != null)
        try
        {
          localFileOutputStream.close();
        }
        catch (IOException localIOException4)
        {
          localIOException4.printStackTrace();
        }
    }
    if (EMLog.debugMode)
    {
      File localFile = new File(paramString);
      DecimalFormat localDecimalFormat = new DecimalFormat("#.##");
      double d1 = localFile.length() / paramArrayOfByte.length * 100.0D;
      double d2 = Double.valueOf(localDecimalFormat.format(d1)).doubleValue();
      EMLog.d("zip", "data size:" + paramArrayOfByte.length + " zip file size:" + localFile.length() + "zip file ratio%: " + d2);
    }
    return true;
  }

  public static String getAppResourceString(Context paramContext, String paramString)
  {
    String str = (String)resourceTable.get(paramString);
    if (str != null)
      return str;
    int i = paramContext.getResources().getIdentifier(paramString, "string", paramContext.getPackageName());
    str = paramContext.getString(i);
    if (str != null)
      resourceTable.put(paramString, str);
    return str;
  }

  public static String convertByteArrayToString(byte[] paramArrayOfByte)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    byte[] arrayOfByte = paramArrayOfByte;
    int j = paramArrayOfByte.length;
    for (int i = 0; i < j; i++)
    {
      byte b = arrayOfByte[i];
      localStringBuffer.append(String.format("0x%02X", new Object[] { Byte.valueOf(b) }));
    }
    return localStringBuffer.toString();
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     com.easemob.util.EasyUtils
 * JD-Core Version:    0.6.1
 */